const user = require("../sql/user")
const sql = require("../sql")
const jwt = require("jsonwebtoken")

module.exports = (req, res)=>{
    // 接收并处理前端数据
    const info = req.body;
    info.age = info.age-0;
    info.tel = info.tel-0;
    info.isMarried = Boolean(info.isMarried-0);
    info.hobby = info.hobby.split(",");
    // 验证token是否失效
    jwt.verify(info.token, "杨树林er", (err, data)=>{
        if(err){
            res.send({code:0, msg:"登录失效"});
        }else{
            // 根据用户名，修改用户信息
            sql.set(user, {username: info.username}, info).then(()=>{
                res.send({code:1, msg:"修改成功"});
            })
        }
    })
}